package com.sims.action.ScoreRecord;

import java.sql.Timestamp;

import org.springframework.beans.factory.annotation.Autowired;

import com.sims.bean.ScoreRecord;
import com.sims.bean.Student;
import com.sims.service.ScoreRecordService;
import com.sims.util.ActionEnhanced;
import com.sims.util.Constant;

@SuppressWarnings("serial")
public class AddScoreRecordAction extends ActionEnhanced{
	
	private ScoreRecord scoreRecord;
	private String year;
	private Integer semester;
	@Autowired
	private ScoreRecordService scoreRecordService;
	public ScoreRecord getScoreRecord() {
		return scoreRecord;
	}
	public void setScoreRecord(ScoreRecord scoreRecord) {
		this.scoreRecord = scoreRecord;
	}
	public String getYear() {
		return year;
	}
	public void setYear(String year) {
		this.year = year;
	}
	public Integer getSemester() {
		return semester;
	}
	public void setSemester(Integer semester) {
		this.semester = semester;
	}
	@Override
	public String execute() {
		if (semester.equals(1)) semester = 12;
		else semester = 6;
		
		Timestamp timestamp = Timestamp.valueOf("year-semester-00"
				.replaceAll("year", year)
				.replaceAll("semester", semester.toString()));
		
		scoreRecord.setStime(timestamp);
		
		result = scoreRecordService.addScoreRecord(scoreRecord);
		if (result.containsKey(Constant.SUCCESS)) {
			System.out.println("success");
			return SUCCESS;
		}
		return ERROR;
	}
}
